<template>
  <div class="wrap">
    <div class="show-title">
      <span>API访问统计</span>
    </div>
    <!-- 搜索 -->
    <div class="searchBox">
      <el-input
        prefix-icon="el-icon-search"
        v-model="searchTableInfo"
        placeholder="请输入搜索内容"
        style="width:30%"
        clearable
      ></el-input>
    </div>
    <!-- 列表 -->
    <el-table
      ref="table"
      :data="tableData.slice((currpage - 1) * pagesize, currpage * pagesize)"
      border
      style="width: 100%"
      stripe
      @selection-change="handleSelectionChange"
      @sort-change="changeSort"
      :row-key="getRowKeys"
    >
      <el-table-column type="selection" width="40" align="center" :reserve-selection="true"></el-table-column>
      <el-table-column prop="API" label="API" min-width="160" align="center" sortable="true">
        <template slot-scope="scope">{{scope.row.API}}</template>
      </el-table-column>
      <el-table-column prop="total" label="访问总数" min-width="160" align="center" sortable>
        <template slot-scope="scope">{{scope.row.total}}</template>
      </el-table-column>
      <el-table-column prop="lastDay" label="最近一天访问量" min-width="160" align="center">
        <template slot-scope="scope">{{scope.row.lastDay}}</template>
      </el-table-column>
      <el-table-column prop="latestTime" label="最后访问时间" min-width="160" align="center" sortable>
        <template slot-scope="scope">{{scope.row.latestTime}}</template>
      </el-table-column>
      <el-table-column prop="maxConcurrent" label="最大并发量" min-width="160" align="center" sortable>
        <template slot-scope="scope">{{scope.row.maxConcurrent}}</template>
      </el-table-column>
      <el-table-column
        prop="lastTenSeconds"
        label="最近10秒并发数"
        min-width="160"
        align="center"
        sortable
      >
        <template slot-scope="scope">{{scope.row.lastTenSeconds}}</template>
      </el-table-column>
      <el-table-column prop="APIdesc" label="API说明" min-width="160" align="center" sortable>
        <template slot-scope="scope">{{scope.row.APIdesc}}</template>
      </el-table-column>
      <el-table-column class="play-box" label="操作" min-width="160" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button size="small" type="success" @click="delRow(scope.$index, scope.row)">刷新</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      right
      background
      layout="total,prev, pager, next, sizes,jumper"
      :page-sizes="[5,10,15,25]"
      :page-size="pagesize"
      :total="tableData.length"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>

    <!--删除全部设备  -->
    <!-- <div class="batch-btn-con">
      <el-button class="batchDelect" type="warning" plain @click="batchDelete">批量删除</el-button>
      <el-link
        class="tips"
        :underline="false"
        type="info"
        icon="el-icon-warning-outline"
      >删除：从网关本地删除摄像机。已经上传状态，删除不了。</el-link>
    </div>-->
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
export default {
  name: "",
  props: {},
  data() {
    return {
      currpage: 1, //分页
      pagesize: 5, //分页
      searchTableInfo: "", //搜索条件
      getSearchInfo: [], //搜索后，过滤后的tableData数据
      tableChecked: [], // 多选
      batchDelectId: [], //批量删除id
      checkAll: false // 是否全选状态
    };
  },
  computed: {
    // 根据计算属性模糊搜索
    tableData() {
      const searchTableInfo = this.searchTableInfo;
      //console.log(searchTableInfo);
      if (searchTableInfo) {
        return this.getSearchInfo.filter(item => {
          return Object.keys(item).some(key => {
            return (
              String(item[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            );
          });
        });
      }
      return this.getSearchInfo;
    },
    //刷新table
    submitData() {
      return this.$store.state.submitData;
    }
  },
  watch: {
    //刷新table
    submitData(newVal, oldVal) {
      if (newVal != oldVal) {
        this.getList();
        this.currpage = 1;
      }
    }
  },
  created() {},
  mounted() {
    this.getList();
  },
  methods: {
    // 获取row的key值
    getRowKeys(row) {
      return row.org_id;
    },
    //点击 第几页
    handleCurrentChange(cpage) {
      this.currpage = cpage;
    },
    //每页有几条
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    //操作多选
    handleSelectionChange(val) {
      var that = this;
      this.batchDelectId = [];
      that.tableChecked = val;
     // console.log(that.tableChecked);
      if (val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          this.batchDelectId.push(val[i]["role_id"]);
        }
      }
    },
    //排序
    changeSort(val) {
     // console.log(val);
    },
    //获取初始列表数据
    getList() {
      
      var apiData = [
        {
          Id: 1,
          API: "测试数据测试数据",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1 1 -1 -1 1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 2,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 3,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 4,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 5,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 6,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 7,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        },
        {
          Id: 8,
          API: "device/list",
          total: "55555",
          lastDay: "2",
          latestTime: "2020-11-01 17:16:01",
          maxConcurrent: "10000",
          lastTenSeconds: "-1 -1 -1",
          APIdesc: "获取设备列表",
          refresh: "刷新"
        }
      ];
      //this.getSearchInfo = apiData;
    },
    //删除单行
    delRow(index, rows) {
    
    }
  }
};
</script>
<style scoped>
/* 更改table,表头背景 */
.wrap >>> .el-table--border th,
.el-table__fixed-right-patch {
  /* background: #c0dee2; */
  background: #f0f3f4;
}
.wrap {
  margin-top: 20px;
  background-color: #fff;
  padding: 15px;
  overflow: hidden;
}
.searchBox {
  margin-bottom: 20px;
}
.wrap >>> .el-pagination {
  float: right;
  margin-top: 30px;
}

.batch-btn-con {
  background: #fff;
  margin-top: 70px;
}
.wrap >>> .tips {
  margin-top: 10px;
  display: block;
  font-size: 15px;
}
/*title*/
.show-title {
  width: 100%;
  height: 40px;
  line-height: 40px;
  position: relative;
  background: #c0dee2;
  padding-left: 15px;
  font-size: 14px;
  margin: 6px 0 20px 0;
  border-radius: 12px 12px 0 0;
  font-weight: bold;
}

.show-title::before {
  content: "";
  width: 2px;
  height: 16px;
  background: #676a6d;
  position: absolute;
  top: 12px;
  left: 27px;
}

.show-title span {
  float: left;
  color: #676a6d;
  margin-left: 25px;
}
</style>
